package main

import (
	"fmt"
	"math/rand"
	"os"
	"strings"
	"time"

	"log"
)

var letterBytes = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var keys = map[string]int{
	"key10":   10,
	"key20":   20,
	"key50":   50,
	"key100":  100,
	"key200":  200,
	"key1000": 1000,
	"key5000": 5000,
}

func init() {
	rand.Seed(time.Now().UnixNano())
}

func main() {
	createFile()
}

func randStringBytes(n int) string {
	b := make([]byte, n)
	for i := range b {
		b[i] = letterBytes[rand.Intn(len(letterBytes))]
	}
	return string(b)
}

func createFile() {
	count := 100000
	for k, size := range keys {
		fd, err := os.OpenFile(fmt.Sprintf("%s.txt", k), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
		if err != nil {
			panic(err)
		}
		val := randStringBytes(size)
		sb := strings.Builder{}
		for i := 0; i < count; i++ {
			key := fmt.Sprintf("%s_%d", k, i)
			cmd := fmt.Sprintf("*3\r\n$3\r\nSET\r\n$%d\r\n%s\r\n$%d\r\n%s\r\n", len(key), key, len(val), val)
			sb.WriteString(cmd)
		}
		if _, err := fd.WriteString(sb.String()); err != nil {
			log.Println(err)
		}
		fd.Close()
	}
}
